package com.application.Tree;

import java.util.ArrayList;
import java.util.List;


import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class ColorAdapter extends ArrayAdapter<CColor> {

	private Context context;
	private CColor[] data;

	public ColorAdapter(Context context, int textViewResourceId,
			CColor[] objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.data = objects;
	}

	public int getCount() {
		return data.length;
	}

	public CColor getItem(int position) {
		return data[position];
	}

	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView label = new TextView(context);
		int color = data[position].color;
		String name = data[position].name;
		label.setTextColor(Color.BLACK);
		label.setText(name);
		label.setBackgroundColor(color);
		return label;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		TextView label = new TextView(context);
		int color = data[position].color;
		String name = data[position].name;
		label.setTextColor(color);
		label.setText(name);
		label.setBackgroundColor(color);
		return label;

	}

}
